package charger;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Output {

	private final static Output instance = new Output();

	public static Output getInstance() {
		return instance;
	}

	private HashMap<String, int[]> liste;

	private Output() {
		liste = new HashMap<>();
	}

	public void lireOut(String fichier) throws IOException {

		InputStream ips = new FileInputStream(fichier);
		InputStreamReader ipsr = new InputStreamReader(ips);
		BufferedReader br = new BufferedReader(ipsr);

		String ligne;
		int[] note = new int[5];
		String id;

		while ((ligne = br.readLine()) != null) {
			StringTokenizer chaine = new StringTokenizer(ligne, " ");
			id = chaine.nextToken();
			chaine.nextToken();
			note = decoupenote(chaine);
			liste.put(id, note);
		}

		br.close();
	}

	private int[] decoupenote(StringTokenizer ligne) {
		int n[] = new int [5];
		
		for(int i=0 ;i<5;i++)
		{
			StringTokenizer chaine = new StringTokenizer(ligne.nextToken(),":");
			chaine.nextToken();
			n[i]= Integer.parseInt(chaine.nextToken());
		}
		
		return n;
	}

	public int[] getNotes(String id) {
		return liste.get(id);
	}
	
}
